package com.keda.service;

import com.keda.dao.*;
import com.keda.model.*;

import java.util.List;

public class IndexService {


    public List<BigType> findBigType() {

        // 查询所有的大分类
        BigTypeDao bigTypeDao = new BigTypeDao();
        // return bigTypeDao.queryBigType(); // 不推荐，不方便调试，因此采用变量形式
        List<BigType> bigTypeList = bigTypeDao.queryBigType();
        // 遍历大分类，然后获取大分类下的小分类
        SmallTypeDao smallTypeDao = new SmallTypeDao();
        for(BigType bigType : bigTypeList) {
            List<SmallType> smallTypes = smallTypeDao.queryByBigType(bigType.getId());
            bigType.setSmallTypes(smallTypes);
        }
        return bigTypeList;
    }

    public List<Tag> findTags() {
        TagDao tagDao = new TagDao();
        List<Tag> tags = tagDao.queryTags();
        return tags;
    }

    public List<Product> findSpecialProducts() {
        ProductDao productDao = new ProductDao();
        List<Product> products = productDao.querySpecialProducts();
        return products;

    }

    public List<Product> findHotProducts() {
        ProductDao productDao = new ProductDao();
        List<Product> products = productDao.queryHotProducts();
        return products;
    }

    public List<Notice> findLatestNotice() {

        NoticeDao noticeDao = new NoticeDao();
        List<Notice> notices = noticeDao.queryNotices();
        return notices;
    }

    public List<News> findLatestNews() {
        NewsDao newsDao = new NewsDao();
        List<News> news = newsDao.queryNews();
        return news;
    }
}
